package org.hales.pojo;


import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class Role implements Serializable {

  private Integer roleId;

  private String roleName;

  private String roleDesc;

  private String createUser;

  private Date createDate;

  private String lastEditUser;

  private Date lastEditDate;

  private Integer active;

  private String rights;

  private String appRoleRights;

  @Data
  public static class RightItem {
    @ApiModelProperty(value = "权限结点ID集合", hidden = true)
    private Integer[] nodeID;

    @ApiModelProperty(value = "权限内容集合", hidden = true)
    private String[] keyWord;
  }

  /**
   * 将权限Json字符串转换成对象
   *
   * @param rights 权限
   * @return
   */
  public static RightItem convertRightItem(String rights) throws Exception {
    RightItem rightItem = null;

    try {
      rightItem = new ObjectMapper().readValue(rights, RightItem.class);
    } catch (Exception e) {
      throw new Exception(e);
    }

    return rightItem;
  }

  private static final long serialVersionUID = 1L;
}
